/******************** 
	作用:粉丝代理
	作者:蔡俊雄
	版本:V1.0
	时间:2015-07-27
********************/

$(function() {
	var tableId = "#dynamic-table"; //表格ID
	var treeUrl = "/shop/admin/user/Team?html=tree"; //团队树的网址
	var manageUrl = "/shop/admin/user/Users/get?html=manage"; //管理的网址
	var getAppsUrl = "/app/getList"; //获取应用列表



	General.initCheckbox(); //初始化表格中的复选框事件监听
	General.extendDialog(); //扩展对话框
	General.initAutoPostSelect(); //初始化页面中所有自动跳转的下拉列表



	//-----------------添加到分组-----------------
	//点击"添加到分组"按钮
	/*$("#sureAdd").on("click", function(e) {
		//判断是否有行被选中
		var selectedRows = $(tableId+' > tbody input[type=checkbox]:checked');
		if (selectedRows.length > 0) {
			//判断是否选中了分组
			if($("#addToGroup").val()=="0"){
				General.alert("请先选中要添加到的分组");
				return false;
			}
			return true;
		} else {
			General.alert("请先选中要添加到分组的粉丝再进行操作!");
			return false;
		}
	});*/
	
	//-----------------查看团队树-----------------
	//点击"团队树"按钮
	$(tableId + ">tbody a[data-id=team]:not([disabled])").on("click", function(e) {
		General.stopEvent(e);
		var tr=$(this).closest("tr");
		var id = tr.attr("data-id");//获取粉丝id
//		var biz_id = tr.attr("data-biz_id");//获取biz_id
//		var public_id = tr.attr("data-public_id");//获取public_id
		var title="团队树";
		showTreeDialog(title,id);
	});
	
	//显示"团队树"窗口
	function showTreeDialog(title,id){
		var url = Common.addUrlParameters(treeUrl, {"id": id});
		General.showDialogWidthHeight(title,url,500,0);
	}
	
	//-----------------管理-----------------
	//点击"管理"按钮
	$(tableId + ">tbody a[data-id=manage]:not([disabled])").on("click", function(e) {
		General.stopEvent(e);
		var tr=$(this).closest("tr");
		var id = tr.attr("data-id");//获取粉丝id
//		var biz_id = tr.attr("data-biz_id");//获取biz_id
//		var public_id = tr.attr("data-public_id");//获取public_id
		var title="管理";
		showManageDialog(title,id);
	});
	
	//显示"管理"窗口
	function showManageDialog(title,id){
		var url = Common.addUrlParameters(manageUrl, {"id": id});
		var maxWidth=700;
		var maxHeight=580;
		var width = $(window).width(); //获取窗口的宽度
		width = width * 0.9;
		if(width>maxHeight){
			width=maxWidth;
		}else{
			width="90%";
		}
		
		var height = $(window).height(); //获取窗口的高度
		height = height * 0.9;
		if(height>maxHeight){
			height=maxHeight;
		}else{
			height=0;
		}
		General.showDialogWidthHeight(title,url,width,height);
	}
	
	//-----------------升级V客-----------------
	//点击"升级V客"按钮
	$(tableId + ">tbody a[data-id=vke]:not([disabled])").on("click", function(e) {
		if (confirm("确定要升级为V客吗?")) {
			return true;
		}else{
			General.stopEvent(e);
		}
	});
	
	//-----------------升级代理-----------------
	//点击"升级代理"按钮
	$(tableId + ">tbody a[data-id=agent]:not([disabled])").on("click", function(e) {
		General.stopEvent(e);
		var id = $(this).closest("tr").attr("data-id");//获取粉丝id
		var title="升级代理";
		showAgentDialog(title,id);
	});
	
	//显示"升级代理"窗口
	function showAgentDialog(title,id){
		var url = Common.addUrlParameters(upgradeToAgentUrl, {"id": id});
		var height = $(window).height(); //获取窗口的高度
		height = height * 0.9;
		var maxHeight=670;
		if(height>maxHeight){
			height=maxHeight;
		}else{
			height=0;
		}
		General.showDialogWidthHeight(title,url,500,height);
	}
	
	//-----------------模拟登陆-----------------
	//点击"模拟登陆"按钮
	$(tableId + ">tbody a[data-id=simulateLogin]:not([disabled])").on("click", function(e) {
		General.stopEvent(e);
		var uid = $(this).closest("tr").attr("data-authid");//获取粉丝id
		var title="选择应用";
		showSimulateLoginDialog(title,uid);
	});
	
	//显示"模拟登陆"窗口
	function showSimulateLoginDialog(title,uid){
		var url = Common.addUrlParameters(getAppsUrl, {"uid": uid});
		var height = $(window).height(); //获取窗口的高度
		General.showDialogWidthHeight(title,url,500,height);
	}
});